{include file="common/_header-css"}
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="sort" class="layui-form-label">
                    <span class="x-red">*</span>上级部门</label>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" class="layui-input" disabled
                           placeholder="上级部门"value="{notempty name='parent'}{$parent.department}{else /}无上级目录{/notempty}">
                    <input type="hidden" name="parent_id" value="{notempty name='parent'}{$parent.id}{else /}0{/notempty}">
                    <input type="hidden" name="type" value="1">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="department" class="layui-form-label">
                    <span class="x-red">*</span>部门名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="department" name="department" autocomplete="off" class="layui-input" placeholder="请填写部门名称">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="level" class="layui-form-label">
                    <span class="x-red">*</span>部门等级</label>
                <div class="layui-input-inline">
                    <input type="text" id="level" name="level" autocomplete="off" class="layui-input" value="{$level}" disabled>

                </div>
            </div>
            <div class="layui-form-item">
                <label for="layui-btn" class="layui-form-label"></label>
                <button id="layui-btn" class="layui-btn" lay-filter="add" lay-submit="">增加</button>
            </div>
        </form>
    </div>
</div>
{include file="common/_jQuery"}
<script>
    layui.use(['form', 'layer'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //监听提交
            form.on('submit(add)', function(data) {
                if (data.field.department == '') {
                    layer.alert('部门名称不能为空!',{icon:5});
                    return false;
                }
                $.post('{:url(\'department/department\')}',data.field,function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:6,time:500},function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            // parent.layer.close(index);
                            window.parent.location.href='index';
                        });
                    }else{
                        layer.msg(res.msg,{icon:5,time:500});
                    }
                });
                return false;
            });
        });
</script>
</body>

</html>